﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace NXBSaiGon.Account
{
    public partial class Information : System.Web.UI.Page
    {
        private SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NXBSaiGonConnectionString1"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("./Login.aspx");
            }
            
        }

        protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Account/ChangePassword.aspx");
        }

        public DataTable getUserInformation()
        {
            DataTable temp = new DataTable();
            string user = Session["username"].ToString();
            conn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter("select MaKhachHang, TenKhachHang, DiaChi, DienThoai, Email, CMND "
                                                            + "from KhachHang "
                                                            + "where Username = '"+ user +"'", conn );
            conn.Close();
            DataSet ds = new DataSet();
            adapter.Fill(ds, "KhachHang");

            //foreach (DataTable dt in ds.Tables)
            //{
            //    temp = dt.Copy();
            //    break;
            //}

            return ds.Tables[0];
        }

        public void updateUserInformation(int MaKhachHang, string TenKhachHang, string DiaChi, string DienThoai, string Email, string CMND)
        {
            string user = Session["username"].ToString();
            conn.Open();
            SqlCommand cmd = new SqlCommand("UPDATE [KhachHang] "
                                                + "SET [TenKhachHang] = '" + TenKhachHang + "' "
                                                + ",[DiaChi] = '" + DiaChi + "' "
                                                + ",[DienThoai] = '" + DienThoai +"' "
                                                + ",[Email] = '" + Email + "' "
                                                + ",[CMND] = '" + CMND + "'"
                                                + "WHERE [Username] = '" + user + "'", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
    }
}